import 'package:wanAndroid/bean/banner_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class BannerWidget extends StatefulWidget {
  List<BannerData> _bannerList;
  double height;

  @override
  State<StatefulWidget> createState() => _BannerWidget();

  BannerWidget(this._bannerList, {this.height});
}

class _BannerWidget extends State<BannerWidget> {
  @override
  Widget build(BuildContext context) => Container(
        constraints: BoxConstraints(maxWidth: double.infinity),
        height: widget.height,
        child: PageView.builder(
          itemBuilder: (context, pos) {
            return Banner(widget._bannerList[pos]);
          },
          itemCount: widget._bannerList.length,
        ),
      );
}

class Banner extends StatelessWidget {
  BannerData _data;

  Banner(this._data);

  @override
  Widget build(BuildContext context) => Stack(
        alignment: Alignment.center,
        children: [
          Positioned.fill(
            child: Image.network(
              _data.imagePath,
              fit: BoxFit.fitHeight,
            ),
          ),
          Positioned(
            left: 0,
            right: 0,
            bottom: 0,
            child: Container(
              padding: const EdgeInsets.symmetric(
                vertical: 15,
                horizontal: 10,
              ),
              alignment: Alignment.centerLeft,
              height: 50,
              decoration: BoxDecoration(
                color: Color(0x80000000),
              ),
              child: Text(
                "${_data.title}",
                softWrap: true,
                overflow: TextOverflow.ellipsis,
                maxLines: 1,
                style: TextStyle(
                  fontSize: 15,
                  color: Colors.white,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ),
          ),
        ],
      );
}
